
/*
7 avr. 2012 jblanchard 
*/

package org.jcb.model;

import java.util.ArrayList;
import java.util.List;

import android.util.Log;


public class ChineseQuestionnaire {


	
	
public ChineseQuestionnaire(boolean neverEnding) {
		this.neverEnding = neverEnding;
}

private List<DataChineseLanguage> questions = new ArrayList<DataChineseLanguage>();
int current ;
public int getCurrent() {
	return current;
}


public void setCurrent(int current) {
	this.current = current;
}

boolean neverEnding ;
int idTypeQuizz ;
int numQuizz ;
int idQuizz ;

public int getIdQuizz() {
	return idQuizz;
}


public void setIdQuizz(int idQuizz) {
	this.idQuizz = idQuizz;
}


public int getNumQuizz() {
	return numQuizz;
}


public void setNumQuizz(int numQuizz) {
	this.numQuizz = numQuizz;
}


public int getIdTypeQuizz() {
	return idTypeQuizz;
}


public void setIdTypeQuizz(int idQuizz) {
	this.idTypeQuizz = idQuizz;
}


public int getHighScore() {
	int score = 0;
	for (DataChineseLanguage dcl : questions) {
			score += dcl.getNote() ;
	}
	return score ;
}


public int getScore() {
	int score = 0;
	for (DataChineseLanguage dcl : questions) {
		if (dcl.getCorrect() != null && dcl.getCorrect() == Boolean.TRUE) {
			score += dcl.getNote() ;	
		}
	}
	return score ;
}

public boolean hasNext() {
	return (current < getNbQuestion()) ;
}

public DataChineseLanguage nextQuestion() throws EndOfQuestionException {
	current++ ;
	Log.d("TAG", "current=" + current );
	if (current > 2) {
		Log.d("TAG", "currentaaaaaaa=" + current );
		if (neverEnding) {
			current = 0 ;	
		}
		else {
			Log.d("TAG", "currentbbbbbbb=" + current );
			throw new EndOfQuestionException("End of questionnaire !!!");
		}		
	}
	Log.d("TAG", "qqqqqqqqq" + current );
	DataChineseLanguage dcl = questions.get(current) ;	
	return  dcl ;
}


public DataChineseLanguage start() throws Exception {
	current = 0 ;
	DataChineseLanguage dcl = questions.get(current) ;	
	return  dcl ;
}

public DataChineseLanguage end() throws Exception {
	current = getNbQuestion() - 1 ;
	DataChineseLanguage dcl = questions.get(current) ;	
	return  dcl ;
}


public DataChineseLanguage prevQuestion() throws Exception {
	if (current > 0) {
		current-- ;
	}
	else {
		if (neverEnding) {
			current = getNbQuestion() - 1 ;	
		}
		else {
			throw new Exception("End of questionnaire !!!");
		}
	}	
	DataChineseLanguage dcl = questions.get(current) ;	
	return  dcl ;
}

//public void initQuestionnaire() {
//	current = 0 ;
//}

public void addQuestion(DataChineseLanguage data) {
	questions.add(data);
}

public int getNbQuestion() {
	return questions.size();
}

public  DataChineseLanguage getQuestion(int i) {
	return questions.get(i);
}

public String getChineseQuestion() {
	return getChineseQuestion(current);
}

public DataChineseLanguage getDataChinese() {
	return questions.get(current);
}

public String getPinyin() {
	return questions.get(current).getPinyin();
}

public String getTranslation() {
	return questions.get(current).getTranslated();
}


public String getChineseQuestion(int i) {
	return questions.get(i).getChinese();
}

public String getPinyin(int i) {
	return questions.get(i).getPinyin();
}

public String getCarCompose(int i) {
	return questions.get(i).getCarCompose();
}

public String getExample(int i) {
	return questions.get(i).getExemple();
}

public String getTranslation(int i) {
	return questions.get(i).getTranslated();
}


}
